﻿using IM.Easy.Core.Audit;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.Json.Serialization;

namespace IM.Easy.Entity.System
{
    /// <summary>
    /// 菜单实体类
    /// </summary>
    [SugarTable(TableDescription = "菜单实体")]
    public class SysMenu : AuditSnowflakeEntity, IOrderable, ISystem, IActive
    {
        public SysMenu()
        {
            Visible = true;
            IsActive = true;
            IsCache = true;
            IsFrame = false;
            RequiresAuth = true;
            IsDeleted = false;
            IsSystem = false;
        }
        /// <summary>
        /// 菜单名称
        /// </summary>
        [SugarColumn(ColumnDescription = "菜单名称")]
        public string Name { get; set; }

        /// <summary>
        /// 菜单图标
        /// </summary>
        [SugarColumn(ColumnDescription = "菜单图标")]
        public string? Icon { get; set; }

        /// <summary>
        /// 父级菜单ID
        /// </summary>
        [SugarColumn(ColumnDescription = "父级菜单ID")]
        public long ParentId { get; set; }

        /// <summary>
        /// 类型
        /// </summary>
        [SugarColumn(ColumnDescription = "菜单类型")]
        public MenuType MenuType { get; set; }

        /// <summary>
        /// 显示顺序
        /// </summary>
        [SugarColumn(ColumnDescription = "显示顺序")]
        public int Order { get; set; }


        /// <summary>
        /// 显示状态（0显示 1隐藏）
        /// </summary>
        [SugarColumn(ColumnDescription = "显示状态")]
        public bool Visible { get; set; }


        /// <summary>
        /// 是否处于活动状态
        /// </summary>
        [SugarColumn(ColumnDescription = "活动状态")]
        public bool IsActive { get; set; }

        /// <summary>
        /// 是否缓存
        /// </summary>
        [SugarColumn(ColumnDescription = "是否缓存")]
        public bool IsCache { get; set; }

        /// <summary>
        /// 路由地址
        /// </summary>
        [SugarColumn(ColumnDescription = "路由地址")]
        public string? Path { get; set; } = "#";

        /// <summary>
        /// 组件路径
        /// </summary>
        [SugarColumn(ColumnDescription = "组件路径")]
        public string? Component { get; set; }

        /// <summary>
        /// 是否外链 true、是 false、否
        /// </summary>
        [SugarColumn(ColumnDescription = "是否外链")]
        public bool IsFrame { get; set; }

        /// <summary>
        /// 权限字符串
        /// </summary>
        [SugarColumn(IsJson = true, ColumnDescription = "权限字符串", Length = 500)]
        public List<string>? Perm { get; set; }

        /// <summary>
        /// 功能标识符，用来标识前端的权限
        /// </summary>
        [SugarColumn(ColumnDescription = "功能标识符")]
        public string? FuncKey { get; set; }

        /// <summary>
        /// 是否需要认证授权
        /// </summary>
        [SugarColumn(ColumnDescription = "是否需要认证授权")]
        public bool RequiresAuth { get; set; }


        /// <summary>
        /// 子菜单列表
        /// </summary>
        [SugarColumn(IsIgnore = true)]
        [Navigate(NavigateType.OneToMany, nameof(ParentId))]
        public List<SysMenu> Children { get; set; }

        [SugarColumn(IsIgnore = true)]
        public bool HasChildren
        {
            get
            {
                return Children != null && Children.Count > 0;
            }
        }

        /// <summary>
        /// 系统内置
        /// </summary>
        [SugarColumn(ColumnDescription = "系统内置")]
        public bool IsSystem { get; set; }
    }

    /// <summary>
    /// 表示菜单项的类型。
    /// </summary>
    public enum MenuType
    {
        /// <summary>
        /// 目录类型，用于对菜单项进行分组。
        /// </summary>
        Directory,

        /// <summary>
        /// 菜单类型，用于显示导航项。
        /// </summary>
        Menu,

        /// <summary>
        /// 按钮类型，用于执行操作或动作。
        /// </summary>
        Button,

        /// <summary>
        /// 链接类型，用于内部或外部的超链接。
        /// </summary>
        Link
    }

}
